const express = require('express')
const orderService = require('services/order')
const router = express.Router()

router.get('/byDate', async (req, res, next) => {
  const { houseId, startTime } = req.query
  try {
    const result = await orderService.getOrdersByDate(houseId, +startTime)
    res.send(result)
  } catch (e) {
    next(e)
  }
})

router.get('/', async (req, res, next) => {
  const result = await orderService.search(req.query)
  res.send(result)
})

router.get('/:id', async (req, res, next) => {
  res.send(await orderService.get(req.params.id))
})

module.exports = router